package com.ruoyi.web.controller.repair;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.repairCheck.domain.HouseRepairCheck;
import com.ruoyi.repairCheck.service.IHouseRepairCheckService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 维修金额审核Controller
 * 
 * @author ruoyi
 * @date 2023-05-27
 */
@RestController
@RequestMapping("/repair/repairCheck")
public class HouseRepairCheckController extends BaseController
{
    @Autowired
    private IHouseRepairCheckService houseRepairCheckService;

    /**
     * 查询维修金额审核列表
     */
   @GetMapping("/list")
    public TableDataInfo list(HouseRepairCheck houseRepairCheck)
    {
        startPage();
        List<HouseRepairCheck> list = houseRepairCheckService.selectHouseRepairCheckList(houseRepairCheck);
        return getDataTable(list);
    }

    /**
     * 导出维修金额审核列表
     */
    @Log(title = "维修金额审核", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, HouseRepairCheck houseRepairCheck)
    {
        List<HouseRepairCheck> list = houseRepairCheckService.selectHouseRepairCheckList(houseRepairCheck);
        ExcelUtil<HouseRepairCheck> util = new ExcelUtil<HouseRepairCheck>(HouseRepairCheck.class);
        util.exportExcel(response, list, "维修金额审核数据");
    }

    /**
     * 获取维修金额审核详细信息
     */
    @GetMapping(value = "/{checkId}")
    public AjaxResult getInfo(@PathVariable("checkId") Long checkId)
    {
        return AjaxResult.success(houseRepairCheckService.selectHouseRepairCheckByCheckId(checkId));
    }

/*审批拒绝*/
    @Log(title = "审核拒绝", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Long[] checkIds)
    {
        return toAjax(houseRepairCheckService.updateHouseRepairCheckByNo(checkIds,getUsername()));
    }


    /**
     * 审核通过
     */
    @Log(title = "维修金额审核通过", businessType = BusinessType.UPDATE)
	@DeleteMapping("/{checkIds}")
    public AjaxResult remove(@PathVariable Long[] checkIds)
    {
        return toAjax(houseRepairCheckService.updateHouseRepairCheckByYes(checkIds,getUsername()));
    }
}
